// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue';
import vuex from 'vuex';
import App from './App';
import router from './router';
// import less from 'less';
import './assets/styles/reset.css';
import './assets/styles/border.css';
import './assets/styles/iconfont.css';
import store from './store/index.js';
// import toastRegistry from './components/toast/index.js';
// import VueScroller from 'vue-scroller';
// import vuescroll from 'vuescroll';
import echarts from 'echarts';
import Moment from 'moment';
import {
  Form,
  FormModel,
  Input,
  Select,
  Button,
  DatePicker,
  Radio,
  message,
  Layout,
  Menu,
  Breadcrumb,
  Table,
  Switch,
  Checkbox,
  Row,
  Col,
  Icon,
  Popconfirm,
  Upload,
  Modal,
  Tabs,
  Tag,
  Rate,
  Steps,
  Descriptions,
  Result,
  List,
  Avatar,
  InputNumber,
  Spin,
  ConfigProvider,
  Pagination,
  Progress,
} from 'ant-design-vue';

// import 'ant-design-vue/dist/antd.css';

// 这里也可以直接执行 toastRegistry()
// Vue.use(toastRegistry, VueScroller, vuex, vuescroll, less);
Vue.use(Form);
Vue.use(FormModel);
Vue.use(Input);
Vue.use(Button);
Vue.use(Select);
Vue.use(DatePicker);
Vue.use(Radio);
Vue.use(Switch);
Vue.use(Checkbox);
Vue.use(Col);
Vue.use(Row);
Vue.use(Layout);
Vue.use(Menu);
Vue.use(Breadcrumb);
Vue.use(Icon);
Vue.use(Table);
Vue.use(Popconfirm);
Vue.use(Upload);
Vue.use(Modal);
Vue.use(Tabs);
Vue.use(Tag);
Vue.use(Rate);
Vue.use(Result);
Vue.use(Steps);
Vue.use(Descriptions);
Vue.use(List);
Vue.use(Avatar);
Vue.use(InputNumber);
Vue.use(Spin);
Vue.use(ConfigProvider);
Vue.use(Pagination);
Vue.use(Progress);

Vue.prototype.$message = message;
Vue.prototype.$echarts = echarts;
Vue.prototype.$Modal = Modal;
Vue.prototype.$Moment = Moment;

// 全局路由守卫, 必须加上;
router.beforeEach((to, from, next) => {
  // to 代表将要访问的路径;
  // from 代表从哪个路径跳转而来;
  // next 是一个函数, 代表放行;
  if (to.path === '/') return next();
  // 获取缓存的username;
  const username = localStorage.getItem('phone');
  if (!username) {
    return next('/');
  }
  if (to.meta.title) {
    document.title = to.meta.title;
  }
  next();
});

message.config({
  duration: 3, // 持续时间
  top: `150px`, // 到页面顶部距离
  maxCount: 3, // 最大显示数, 超过限制时，最早的消息会被自动关闭
});
Vue.config.productionTip = false;

// new Vue({
//   el: '#app',
//   router,
//   store,
//   components: { App },
//   template: '<App/>',
// });

new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  render: (h) => h(App),
}).$mount('#app');
